﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace ZeroBug.PersonalityEvaluation
{
    public partial class RevisePasswordViewModel : ObservableObject
    {
        [ObservableProperty]
        string newPassword;

        [RelayCommand]
        void RevisePassword()
        {
            if(string.IsNullOrEmpty(newPassword))
            {
                MessageBox.Show("密码不能为空!");
                return;
            }
            string user = App.Current.Services.GetService<DataStatisticsViewModel>().AdminName;
            var databaseHelper = App.Current.Services.GetService<IDatabase>();
            Dictionary<string, object> data = new Dictionary<string, object>();
            data.Add("Password", newPassword);
            Dictionary<string, object> con = new Dictionary<string, object>();
            con.Add("Name", user);
            databaseHelper.UpdateOneRecord("Admin", data, con);

            CloseWindow();
        }
        [RelayCommand]
        void CloseWindow()
        {
            var window = App.Current.Services.GetService<RevisePasswordView>();
            if (window != null)
                SystemCommands.CloseWindow(window);
        }
    }
}
